// 统一请求路径前缀在libs/axios.js中修改
import { getRequest, getRequestToken, postRequestToken, postRequest, exportPost, putRequest, postBodyRequest, getNoAuthRequest, postNoAuthRequest } from '@/libs/axios';

// 下面两个接口是做了本地缓存的 慎用

async function getReqAndLocal(url, params) {
    try {
        let result = await getLocalData(url, params);
        new Promise(() => {
            getRequest(url, params).then(res => {
                console.log('更新成功');
                sessionStorage.setItem(url + JSON.stringify(params), JSON.stringify(res));
            });
        });
        console.log('已经从本地拿到数据了');
        return Promise.resolve(result);
    } catch {
        // 从本地获取失败
        let r = await getRequest(url, params);
        sessionStorage.setItem(url + JSON.stringify(params), JSON.stringify(r));
        console.log('本地无数据，从网络获取');
        return Promise.resolve(r);
    }
}

async function postReqAndLocal(url, params) {
    try {
        let result = await getLocalData(url, params);
        new Promise(() => {
            postRequest(url, params).then(res => {
                console.log('更新成功');
                sessionStorage.setItem(url + JSON.stringify(params), JSON.stringify(res));
            });
        });
        console.log('已经从本地拿到数据了');
        return Promise.resolve(result);
    } catch {
        // 从本地获取失败
        let r = await postRequest(url, params);
        sessionStorage.setItem(url + JSON.stringify(params), JSON.stringify(r));
        console.log('本地无数据，从网络获取');
        return Promise.resolve(r);
    }
}

// Vaptcha ID
export const vaptchaID = config.vaptchaID;
// Vaptcha离线验证接口
export const vaptchaOffline = `${config.baseApi}/common/vaptcha/offline`;
// 文件上传接口
export const uploadFile = `${config.baseApi}/upload/file`;
// 验证码渲染图片接口
export const drawCodeImage = `${config.baseApi}/common/captcha/draw/`;
// 获取菜单
export const getMenuList = `${config.baseApi}/permission/getMenuList`;
// 获取数据字典
export const getDictData = `${config.baseApi}/dictData/getByType/`;
// Websocket
export const ws = `${config.baseApi}/ws`;

// 登陆判斷tap頁
export const loginJud = params => {
    return postNoAuthRequest('/judResource/login', params);
};
// 初始登录接口
export const login = params => {
    return postNoAuthRequest('/login', params);
};

export const getSubmarketInfo = params => {
    return postNoAuthRequest('/submarker/getByUserName', params);
};
// 获取用户登录信息
export const userInfo = params => {
    return getRequest('/user/info', params);
};
export const userInfoToken = (token, params) => {
    return getRequestToken(token, '/user/info', params);
};
// 注册
export const regist = params => {
    return postNoAuthRequest('/user/regist', params);
};
// 初始化验证码
export const initCaptcha = params => {
    return getNoAuthRequest('/common/captcha/init', params);
};
// 发送登录短信验证码
export const sendLoginSms = (mobile, params) => {
    return getNoAuthRequest(`/common/captcha/sendLoginSms/${mobile}`, params);
};
export const sendLoginByUsernameSms = (params) => {
    return getRequest('/province/select/sendLoginSms/byUsername', params);
};

// 发送注册短信验证码
export const sendRegistSms = (mobile, params) => {
    return getNoAuthRequest(`/common/captcha/sendRegistSms/${mobile}`, params);
};
// 发送重置密码短信验证码
export const sendResetSms = (mobile, params) => {
    return getNoAuthRequest(`/common/captcha/sendResetSms/${mobile}`, params);
};

// 发送省级学校首次登录修改密码验证码
export const sendUpdatePassCode = (token, params) => {
    return getRequestToken(token, `/common/captcha/sendUpdatePassCode`, params);
};

// 发送学生激活账号验证码
export const sendActivationCode = params => {
    return postRequest(`/common/captcha/sendActivationCode`, params);
};

// 发送学生找回密码验证码
export const sendRetrievePassCode = params => {
    return postRequest(`/common/captcha/sendRetrievePassCode`, params);
};

// 发送修改绑定手机短信验证码
export const sendEditMobileSms = (mobile, params) => {
    return getRequest(`/common/captcha/sendEditMobileSms/${mobile}`, params);
};
// 通过手机重置密码
export const resetByMobile = params => {
    return postNoAuthRequest('/user/resetByMobile', params);
};
//学校用户 信息补充提交
export const modifyPassFirstLogin = (token, params) => {
    return postRequestToken(token, '/user/modifyPassFirstLogin', params);
};

// 发送重置密码邮件验证码
export const sendResetEmail = (email, params) => {
    return getNoAuthRequest(`/email/sendResetCode/${email}`, params);
};
// 发送修改绑定邮件验证码
export const sendEditEmail = (email, params) => {
    return getRequest(`/email/sendEditCode/${email}`, params);
};
// 通过邮件重置密码
export const resetByEmail = params => {
    return postNoAuthRequest('/email/resetByEmail', params);
};
// 短信验证码登录
export const smsLogin = params => {
    return postRequest('/user/smsLogin', params);
};
// IP天气信息
export const ipInfo = params => {
    return getRequest('/common/ip/info', params);
};
// 个人中心编辑
export const userInfoEdit = params => {
    return postRequest('/user/edit', params);
};
// 个人中心发送修改邮箱验证邮件
export const sendCodeEmail = (email, params) => {
    return getRequest(`/email/sendCode/${email}`, params);
};
// 个人中心发送修改邮箱验证邮件
export const editEmail = params => {
    return postRequest('/email/editEmail', params);
};
// 个人中心修改密码
export const changePass = params => {
    return postRequest('/user/modifyPass', params);
};
// 个人中心修改手机
export const changeMobile = params => {
    return postRequest('/user/changeMobile', params);
};
// 解锁
export const unlock = params => {
    return postRequest('/user/unlock', params);
};
// 获取公告
export const getNotice = params => {
    return getNoAuthRequest('/setting/notice', params);
};

// github登录
export const githubLogin = params => {
    return getNoAuthRequest('/social/github/login', params);
};
// qq登录
export const qqLogin = params => {
    return getNoAuthRequest('/social/qq/login', params);
};
// 微博登录
export const weiboLogin = params => {
    return getNoAuthRequest('/social/weibo/login', params);
};
// 微信登录
export const wechatLogin = params => {
    return getNoAuthRequest('/social/wechat/login', params);
};
// 钉钉登录
export const dingdingLogin = params => {
    return getNoAuthRequest('/social/dingding/login', params);
};
// 企业微信登录
export const workwechatLogin = params => {
    return getNoAuthRequest('/social/workwechat/login', params);
};
// 绑定账号
export const relate = params => {
    return postRequest('/social/relate', params);
};
// 获取JWT
export const getJWT = params => {
    return getNoAuthRequest('/social/getJWT', params);
};

// 获取绑定账号信息
export const relatedInfo = (username, params) => {
    return getRequest(`/relate/getRelatedInfo/${username}`, params);
};
// 解绑账号
export const unRelate = params => {
    return postRequest('/relate/delByIds', params);
};
// 分页获取绑定账号信息
export const getRelatedListData = params => {
    return getRequest('/relate/findByCondition', params);
};

// 获取用户数据 多条件
export const getUserListData = params => {
    return getRequest('/user/getByCondition', params);
};
// 通过用户名搜索
export const searchUserByName = (username, params) => {
    return getRequest('/user/searchByName/' + username, params);
};
// 获取全部用户数据
export const getAllUserData = params => {
    return getRequest('/user/getAll', params);
};
// 获取全部学校信息数据
export const getAllSchoolData = () => {
    return postRequest('/schoolCode/getAll');
};

// 拿到全部学校信息带缓存
export const getAllSchoolDataByLocal = () => {
    return postReqAndLocal('/schoolCode/getAll');
};

export const searchSchoolName = () => {
    return postRequest('/schoolCode/searchSchool');
};
export const getSchool = params => {
    return postRequest('/schoolCode/getBypage', params);
};

export const getSchoolCode = () => {
    return postRequest('/schoolCode/getByCode');
};
// 获取全部学校账号信息数据
export const getSchoolPersonInfoData = () => {
    return postRequest('/schoolPersonInfo/getAll');
};
// 获取全部二级学院账号数据
export const getCollegePersonInfoData = () => {
    return postRequest('/collegePersonInfo/getAll');
};
// 获取全部数据汇总
export const getByYxCodeAll = params => {
    return postRequest('/schoolCode/getByYxCodeAll', params);
};
// 通过部门获取全部用户数据
export const getUserByDepartmentId = (id, params) => {
    return getRequest(`/user/getByDepartmentId/${id}`, params);
};
// 添加用户
export const addUser = params => {
    console.log(params, 'pa');
    return postRequest('/user/admin/add', params);
};
// 编辑用户
export const editUser = params => {
    return postRequest('/user/admin/edit', params);
};
// 启用用户
export const enableUser = (id, params) => {
    return postRequest(`/user/admin/enable/${id}`, params);
};
// 禁用用户
export const disableUser = (id, params) => {
    return postRequest(`/user/admin/disable/${id}`, params);
};
// 删除用户
export const deleteUser = params => {
    return postRequest('/user/delByIds', params);
};
// 导入用户
export const importUserData = params => {
    return postBodyRequest('/user/importData', params);
};
// 重置用户密码
export const resetUserPass = params => {
    return postRequest('/user/resetPass', params);
};

// 导入字典数据
export const importDictData = params => {
    return postBodyRequest('/dictData/importDictData', params);
};

//导入学校代码数据
export const importSchoolData = params => {
    return postBodyRequest('/schoolCode/importSchoolData', params);
};

//导入省级账号数据
export const importProvinceData = params => {
    return postBodyRequest('/provicePersonInfo/importProvincePersonInfo', params);
};
//导入学校账号数据
export const importschoolPersonData = params => {
    return postBodyRequest('/schoolPersonInfo/importSchoolPersonInfo', params);
};
// 导入毕业生档案转递信息
export const importArchiveTransferInfoData = params => {
    return postBodyRequest('/archiveTransferInfo/importArchiveTransferInfo', params);
};

// 获取一级部门
export const initDepartment = params => {
    return getRequest('/department/getByParentId/0', params);
};
// 加载部门子级数据
export const loadDepartment = (id, params) => {
    return getRequest(`/department/getByParentId/${id}`, params);
};
// 添加部门
export const addDepartment = params => {
    return postRequest('/department/add', params);
};
// 编辑部门
export const editDepartment = params => {
    return postRequest('/department/edit', params);
};
// 删除部门
export const deleteDepartment = params => {
    return postRequest('/department/delByIds', params);
};
// 搜索部门
export const searchDepartment = params => {
    return getRequest('/department/search', params);
};

// 获取全部角色数据
export const getAllRoleList = params => {
    return getRequest('/role/getAllList', params);
};

// 获取部分角色数据
export const getRoles = params => {
    return postRequest('/role/getRoleList', params);
};

// 分页获取角色数据
export const getRoleList = params => {
    return getRequest('/role/getAllByPage', params);
};
// 添加角色
export const addRole = params => {
    return postRequest('/role/save', params);
};
// 编辑角色
export const editRole = params => {
    return postRequest('/role/edit', params);
};
// 设为或取消注册角色
export const setDefaultRole = params => {
    return postRequest('/role/setDefault', params);
};
// 分配角色权限
export const editRolePerm = params => {
    return postRequest('/role/editRolePerm', params);
};
// 分配角色数据权限
export const editRoleDep = params => {
    return postRequest('/role/editRoleDep', params);
};
// 删除角色
export const deleteRole = params => {
    return postRequest('/role/delByIds', params);
};

// 获取全部权限数据
export const getAllPermissionList = params => {
    return getRequest('/permission/getAllList', params);
};
// 加载数据
export const loadPermission = (id, params) => {
    return getRequest(`/permission/getByParentId/${id}`, params);
};
// 添加权限
export const addPermission = params => {
    return postRequest('/permission/add', params);
};
// 编辑权限
export const editPermission = params => {
    return postRequest('/permission/edit', params);
};
// 删除权限
export const deletePermission = params => {
    return postRequest('/permission/delByIds', params);
};
// 搜索权限
export const searchPermission = params => {
    return getRequest('/permission/search', params);
};

// 获取全部字典
export const getAllDictList = params => {
    return getRequest('/dict/getAll', params);
};
// 添加字典
export const addDict = params => {
    return postRequest('/dict/add', params);
};
// 编辑字典
export const editDict = params => {
    return postRequest('/dict/edit', params);
};
// 删除字典
export const deleteDict = params => {
    return postRequest('/dict/delByIds', params);
};
// 搜索字典
export const searchDict = params => {
    return getRequest('/dict/search', params);
};
// 获取全部字典数据
export const getAllDictDataList = params => {
    return getRequest('/dictData/getByCondition', params);
};
// 添加字典数据
export const addDictData = params => {
    return postRequest('/dictData/add', params);
};
// 编辑字典数据
export const editDictData = params => {
    return postRequest('/dictData/edit', params);
};
// 删除字典数据
export const deleteData = params => {
    return postRequest('/dictData/delByIds', params);
};
// 通过类型获取字典数据
export const getDictDataByType = (type, params) => {
    return getRequest(`/dictData/getByType/${type}`, params);
};

// 通过类型获取字典数据(分页）
export const getDictDataByTypeAndPage = params => {
    return postRequest(`/dictData/getByTypeAndPage`, params);
};

// 通过类型获取字典数据
export const getDictDataByTypePost = params => {
    return postRequest(`/dictData/getByTypePost`, params);
};

// 分页获取日志数据
export const getLogListData = params => {
    return getRequest('/log/getAllByPage', params);
};
// 删除日志
export const deleteLog = params => {
    return postRequest('/log/delByIds', params);
};
// 清空日志
export const deleteAllLog = params => {
    return postRequest('/log/delAll', params);
};

// 分页获取监控记录
export const getMonitorRecordListData = params => {
    return getRequest('/monitor/getAllByPage', params);
};
// 删除监控记录
export const deleteMonitorRecord = params => {
    return postRequest('/monitor/delByIds', params);
};
// 清空监控记录
export const deleteAllMonitorRecord = params => {
    return postRequest('/monitor/delAll', params);
};



// 分页获取Redis数据
export const getRedisData = params => {
    return getRequest('/redis/getAllByPage', params);
};
// 通过key获取Redis信息
export const getRedisByKey = (key, params) => {
    return getRequest(`/redis/getByKey/${key}`, params);
};
// 获取Redis键值数量
export const getRedisKeySize = params => {
    return getRequest('/redis/getKeySize', params);
};
// 获取Redis内存
export const getRedisMemory = params => {
    return getRequest('/redis/getMemory', params);
};
// 获取Redis信息
export const getRedisInfo = params => {
    return getRequest('/redis/info', params);
};
// 添加编辑Redis
export const saveRedis = params => {
    return postRequest('/redis/save', params);
};
// 删除Redis
export const deleteRedis = params => {
    return postRequest('/redis/delByKeys', params);
};
// 清空Redis
export const deleteAllRedis = params => {
    return postRequest('/redis/delAll', params);
};

// 分页获取定时任务数据
export const getQuartzListData = params => {
    return getRequest('/quartzJob/getAllByPage', params);
};
// 添加定时任务
export const addQuartz = params => {
    return postRequest('/quartzJob/add', params);
};
// 编辑定时任务
export const editQuartz = params => {
    return postRequest('/quartzJob/edit', params);
};
// 暂停定时任务
export const pauseQuartz = params => {
    return postRequest('/quartzJob/pause', params);
};
// 恢复定时任务
export const resumeQuartz = params => {
    return postRequest('/quartzJob/resume', params);
};
// 手动执行一次任务
export const doOnce = params => {
    return postRequest('/quartzJob/doOnce', params);
};
// 删除定时任务
export const deleteQuartz = params => {
    return postRequest('/quartzJob/delByIds', params);
};

// 分页获取消息数据
export const getMessageData = params => {
    return getRequest('/message/getByCondition', params);
};
// 获取单个消息详情
export const getMessageDataById = (id, params) => {
    return getRequest(`/message/get/${id}`, params);
};
// 添加消息
export const addMessage = params => {
    return postRequest('/message/add', params);
};
// 编辑消息
export const editMessage = params => {
    return postRequest('/message/edit', params);
};
// 删除消息
export const deleteMessage = params => {
    return postRequest('/message/delByIds', params);
};
// 分页获取消息推送数据
export const getMessageSendData = params => {
    return getRequest('/messageSend/getByCondition', params);
};
// 编辑发送消息
export const editMessageSend = params => {
    return postRequest('/messageSend/edit', params);
};
// 删除发送消息
export const deleteMessageSend = params => {
    return postRequest('/messageSend/delByIds', params);
};
// 批量处理消息
export const allMessageSend = (type, params) => {
    return getRequest(`/messageSend/all/${type}`, params);
};

// 分页获取文件数据
export const getFileListData = params => {
    return getRequest('/file/getByCondition', params);
};
// 复制文件
export const copyFile = params => {
    return postRequest('/file/copy', params);
};
// 重命名文件
export const renameFile = params => {
    return postRequest('/file/rename', params);
};
// 删除文件
export const deleteFile = params => {
    return postRequest('/file/delete', params);
};
// 下载文件
export const aliDownloadFile = (fKey, params) => {
    return getRequest(`/file/ali/download/${fKey}`, params);
};

// 检查oss配置
export const checkOssSet = params => {
    return getRequest('/setting/oss/check', params);
};
// 检查oss配置
export const checkSmsSet = params => {
    return getRequest('/setting/sms/check', params);
};
// 获取oss配置
export const getOssSet = (serviceName, params) => {
    return getRequest(`/setting/oss/${serviceName}`, params);
};
// 编辑oss配置
export const editOssSet = params => {
    return postRequest('/setting/oss/set', params);
};
// 获取sms配置
export const getSmsSet = (serviceName, params) => {
    return getRequest(`/setting/sms/${serviceName}`, params);
};
// 获取sms模板code
export const getSmsTemplateCode = (serviceName, type, params) => {
    return getRequest(`/setting/sms/templateCode/${serviceName}/${type}`, params);
};
// 编辑sms配置
export const editSmsSet = params => {
    return postRequest('/setting/sms/set', params);
};
// 获取email配置
export const getEmailSet = (serviceName, params) => {
    return getRequest('/setting/email', params);
};
// 编辑email配置
export const editEmailSet = params => {
    return postRequest('/setting/email/set', params);
};
// 获取vaptcha配置
export const getVaptchaSet = params => {
    return getRequest('/setting/vaptcha', params);
};
// 编辑vaptcha配置
export const editVaptchaSet = params => {
    return postRequest('/setting/vaptcha/set', params);
};
// 获取vaptcha配置
export const getOtherSet = params => {
    return getRequest('/setting/other', params);
};
// 编辑other配置
export const editOtherSet = params => {
    return postRequest('/setting/other/set', params);
};
// 获取notice配置
export const getNoticeSet = params => {
    return getRequest('/setting/notice', params);
};
// 编辑notice配置
export const editNoticeSet = params => {
    return postRequest('/setting/notice/set', params);
};
// 获取autoChat配置
export const getAutoChatSet = params => {
    return getRequest('/setting/autoChat', params);
};
// 编辑autoChat配置
export const editAutoChatSet = params => {
    return postRequest('/setting/autoChat/set', params);
};
// 查看私密配置
export const seeSecretSet = (settingName, params) => {
    return getRequest(`/setting/seeSecret/${settingName}`, params);
};

// 表格生成
export const generateTable = (name, rowNum, params) => {
    return postBodyRequest(`/generate/table/${name}/${rowNum}`, params);
};
// 树生成
export const generateTree = (name, rowNum, enableTable, params) => {
    return postBodyRequest(`/generate/tree/${name}/${rowNum}/${enableTable}`, params);
};
// 通过实体类生成Vue代码Json数据
export const getEntityData = params => {
    return getRequest('/generate/getEntityData', params);
};

// 分页获取禁用词
export const getStopWordData = params => {
    return getRequest('/stopWord/getByCondition', params);
};
// 添加禁用词
export const addStopWord = params => {
    return postRequest('/stopWord/save', params);
};
// 编辑禁用词
export const editStopWord = params => {
    return postRequest('/stopWord/edit', params);
};
// 删除禁用词
export const deleteStopWord = params => {
    return postRequest('/stopWord/delByIds', params);
};

// base64上传
export const base64Upload = params => {
    return postRequest('/upload/file', params);
};

// 获取版本号列表
export const getVersionList = params => {
    return postRequest('/dict/getVersions', params);
};

// 导出数据汇总所有
export const exportAllSjhz = params => {
    return exportPost('/bysPersonInfo/exportSyzl', params);
};
